<extend name="public@base5" />
<block name="head">
    <include file="theme/functions" />
</block>
<block name="main">
    <div class="wrap " style="text-align: center;">
        <form class="js-ajax-form margin-top-20" role="form" action="{:url('Promote/userLevelDefinePost')}" method="post">
            <foreach name="level_define_array" item="vo" key="index">
                <div class="row margin-top-10">
                    <div class="col-10">
                    <input type="number" name="level_define_post[{$index}][id]" value="{$vo.id}" hidden>
                    等级{$vo.user_level}升级需要完成直推用户：
                    <input type="number" name="level_define_post[{$index}][condition_invite]" value="{$vo.condition_invite}">
                    个，团队用户：
                    <input type="number" name="level_define_post[{$index}][condition_team]" value="{$vo.condition_team}">
                    个，奖励团队用户收益的
                    <input type="number" name="level_define_post[{$index}][reward_percent]" value="{:number_format($vo.reward_percent/100,2)}">
                    %
                    勋章ID<input class="medal_id" id="medal_id_{$index}" data-idx="{$index}" type="number" name="level_define_post[{$index}][medal_id]" value="{$vo.medal_id}">
                    </div>
                    <div class="col-2 text-start"><label class="medal_info" id="medal_info_{$index}"></label></div>
                </div>
            </foreach>
            <div class="form-group margin-top-20">
                <button type="submit" class="btn btn-primary js-ajax-submit" data-refresh="1">
                    {:lang('SAVE')}
                </button>
            </div>
        </form>
    </div>
</block>
<block name="scripts">
    <include file="theme/scripts" />
    <script>
        /***/
        function check_medal(idx){
           var metId = $('#medal_id_'+idx).val();
           var info_id = '#medal_info_'+idx;
           if(metId>0){
               $.get('{:url("task/medal_info")}',{"id":metId},function(d){
                   if(d && d.data && d.data.id){
                       var data = d.data;
                       var html = data.medal_name;
                       $(info_id).html(html);
                   }else{
                       $(info_id).html('');
                   }
               });
           }else{
               $(info_id).html('');
           }
        }
        
        function on_change(){
            var $this = $(this);
            var idx = $this.data('idx');
            check_medal(idx);
        }
        
        $('.medal_id').on('change',on_change);
        $('.medal_id').each(function(idx,d){
            var idx = $(d).data('idx');
            check_medal(idx);
        });
    </script>
</block>